package com.purchase.manage.controller;

import com.purchase.common.core.domain.AjaxResult;
import com.purchase.manage.damian.OrderQuotations;
import com.purchase.manage.mapper.OrderQuotationMapper;
import com.purchase.manage.mapper.OrderQuotationProductMapper;
import com.purchase.manage.service.impl.OrderQuotationProductServiceImpl;
import com.purchase.manage.service.impl.OrderQuotationServiceImpl;
import com.purchase.manage.untils.GetExcel;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.text.ParseException;

/**
 * <p>
 * 产品询价表 前端控制器
 * </p>
 *
 * @author chuan
 * @since 2023-07-06
 */


@Controller
@RequestMapping("/system")
public class OrderQuotationProductController {
    @Autowired
    OrderQuotationProductServiceImpl orderQuotationProductService;
    @Autowired
    OrderQuotationServiceImpl orderQuotationService;

    @Autowired
    OrderQuotationMapper orderQuotationMapper;
    @Autowired
    OrderQuotationProductMapper orderQuotationProductMapper;



    @PostMapping("/supplier")
    public AjaxResult InsertQuotation(@RequestParam("file") MultipartFile rfile) throws IOException {
        //生成接受数据的对象
        OrderQuotations orderQuotations = null;
        try {
            //获取excel中的数据
            orderQuotations=GetExcel.getOrderQuotations(rfile);
        }catch (IOException e){
            return AjaxResult.error("文件上传的格式不对");
        }catch (ParseException e){
            return AjaxResult.error("文件上传的格式不对");
        }
        //添加订单
        orderQuotationService.insertQuotation(orderQuotations.getOrderQuotation());
        //添加产品
        orderQuotationProductService.insertQuotationProduct(orderQuotations.getOrderQuotationProduct());
        return AjaxResult.success();
    }


}
